home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 7 / Amiga Format AFCD07 (Dec 1996, Issue 91).iso / serious / shareware / programming / emacs-complete / fsf / emacs / info / emacs-16 < prev    next >
Encoding:
GNU Info File  |  1994-10-06  |  44.4 KB  |  1,065 lines

  1. This is Info file ../info/emacs, produced by Makeinfo-1.54 from the
  2. input file emacs.texi.
  3.  
  4. 
  5. File: emacs,  Node: Remote Host,  Prev: Shell Options,  Up: Shell
  6.  
  7. Remote Host Shell
  8. -----------------
  9.  
  10.    Emacs provides two commands for logging in to another computer and
  11. communicating with it through an Emacs buffer.
  12.  
  13. `M-x telnet RET HOSTNAME RET'
  14.      Set up a Telnet connection to the computer named HOSTNAME.
  15.  
  16. `M-x rlogin RET HOSTNAME RET'
  17.      Set up an Rlogin connection to the computer named HOSTNAME.
  18.  
  19.    Use `M-x telnet' to set up a Telnet connection to another computer.
  20. (Telnet is the standard Internet protocol for remote login.) It reads
  21. the host name of the other computer as an argument with the minibuffer.
  22. Once the connection is established, talking to the other computer
  23. works like talking to a subshell: you can edit input with the usual
  24. Emacs commands, and send it a line at a time by typing RET.  The output
  25. is inserted in the Telnet buffer interspersed with the input.
  26.  
  27.    Use `M-x rlogin' to set up an Rlogin connection.  Rlogin is another
  28. remote login communication protocol, essentially much like the Telnet
  29. protocol but incompatible with it, and supported only by certain
  30. systems.  Rlogin's advantages are that you can arrange not to have to
  31. give your user name and password when communicating between two machines
  32. you frequently use, and that you can make an 8-bit-clean connection.
  33. (To do that in Emacs, set `rlogin-explicit-args' to `("-8")' before you
  34. run Rlogin.)
  35.  
  36.    `M-x rlogin' sets up the default file directory of the Emacs buffer
  37. to access the remote host via FTP (*note File Names::.), and it tracks
  38. the shell commands that change the current directory just like Shell
  39. mode.
  40.  
  41. 
  42. File: emacs,  Node: Emacs Server,  Next: Hardcopy,  Prev: Shell,  Up: Top
  43.  
  44. Using Emacs as a Server
  45. =======================
  46.  
  47.    Various programs such as `mail' can invoke your choice of editor to
  48. edit a particular piece of text, such as a message that you are
  49. sending.  By convention, these programs use the environment variable
  50. `EDITOR' to specify which editor to run.  If you set `EDITOR' to
  51. `emacs', they invoke Emacs--but in an inconvenient fashion, by starting
  52. a new, separate Emacs process.  This is inconvenient because it takes
  53. time and because the new Emacs process doesn't share the buffers in the
  54. existing Emacs process.
  55.  
  56.    You can arrange to use your existing Emacs process as the editor for
  57. programs like `mail' by using the Emacs client and Emacs server
  58. programs.  Here is how.
  59.  
  60.    First, the preparation.  Within Emacs, call the function
  61. `server-start'.  (Your `.emacs' file can do this automatically if you
  62. add the expression `(server-start)' to it.)  Then, outside Emacs, set
  63. the `EDITOR' environment variable to `emacsclient'.
  64.  
  65.    Then, whenever any program invokes your specified `EDITOR' program,
  66. the effect is to send a message to your principal Emacs telling it to
  67. visit a file.  (That's what the program `emacsclient' does.) Emacs
  68. obeys silently; it does not immediately switch to the new file's
  69. buffer.  When you want to do that, type `C-x #' (`server-edit').
  70.  
  71.    When you've finished editing that buffer, type `C-x #' again.  This
  72. saves the file and sends a message back to the `emacsclient' program
  73. telling it to exit.  The programs that use `EDITOR' wait for the
  74. "editor" (actually, `emacsclient') to exit.  `C-x #' also checks to see
  75. if any other files are pending for you to edit, and selects the next
  76. one.
  77.  
  78.    You can switch to a server buffer manually if you wish; you don't
  79. have to arrive at it with `C-x #'.  But `C-x #' is the only way to say
  80. that you are "finished" with one.
  81.  
  82.    If you set the variable `server-window' to a window or a frame, `C-x
  83. #' displays the server buffer in that window or in that frame.
  84.  
  85.    While `mail' or another application is waiting for `emacsclient' to
  86. finish, `emacsclient' does not read terminal input.  So the terminal
  87. that `mail' was using is effectively blocked for the duration.  In
  88. order to edit with your principal Emacs, you need to be able to use it
  89. without using that terminal.  There are two ways to do this:
  90.  
  91.    * Using a window system, run `mail' and the principal Emacs in two
  92.      separate windows.  While `mail' is waiting for `emacsclient', the
  93.      window where it was running is blocked, but you can use Emacs by
  94.      switching windows.
  95.  
  96.    * Use Shell mode in Emacs to run the other program such as `mail';
  97.      then, `emacsclient' blocks only the subshell under Emacs, and you
  98.      can still use Emacs to edit the file.
  99.  
  100.    Some programs write temporary files for you to edit.  After you edit
  101. the temporary file, the program reads it back and deletes it.  If the
  102. Emacs server is later asked to edit the same file name, it should assume
  103. this has nothing to do with the previous occasion for that file name.
  104. The server accomplishes this by killing the temporary file's buffer when
  105. you finish with the file.  Use the variable `server-temp-file-regexp'
  106. to specify which files are temporary in this sense; its value should be
  107. a regular expression that matches file names that are temporary.
  108.  
  109. 
  110. File: emacs,  Node: Hardcopy,  Next: Sorting,  Prev: Emacs Server,  Up: Top
  111.  
  112. Hardcopy Output
  113. ===============
  114.  
  115.    The Emacs commands for making hardcopy let you print either an entire
  116. buffer or just part of one, either with or without page headers.  See
  117. also the hardcopy commands of Dired (*note Misc File Ops::.) and the
  118. diary (*note Diary Commands::.).
  119.  
  120. `M-x print-buffer'
  121.      Print hardcopy of current buffer with page headings containing the
  122.      file name and page number.
  123.  
  124. `M-x lpr-buffer'
  125.      Print hardcopy of current buffer without page headings.  makes no
  126.      page headings.
  127.  
  128. `M-x print-region'
  129.      Like `print-buffer' but print only the current region.
  130.  
  131. `M-x lpr-region'
  132.      Like `lpr-buffer' but print only the current region.
  133.  
  134.    All the hardcopy commands pass extra switches to the `lpr' program
  135. based on the value of the variable `lpr-switches'.  Its value should be
  136. a list of strings, each string an option starting with `-'.  For
  137. example, to use a printer named `nearme', set `lpr-switches' like this:
  138.  
  139.      (setq lpr-switches '("-Pnearme"))
  140.  
  141.    The variable `lpr-header-switches' similarly specifies the extra
  142. switches to use to make page headers.
  143.  
  144. 
  145. File: emacs,  Node: Sorting,  Next: Narrowing,  Prev: Hardcopy,  Up: Top
  146.  
  147. Sorting Text
  148. ============
  149.  
  150.    Emacs provides several commands for sorting text in the buffer.  All
  151. operate on the contents of the region (the text between point and the
  152. mark).  They divide the text of the region into many "sort records",
  153. identify a "sort key" for each record, and then reorder the records
  154. into the order determined by the sort keys.  The records are ordered so
  155. that their keys are in alphabetical order, or, for numeric sorting, in
  156. numeric order.  In alphabetic sorting, all upper case letters `A'
  157. through `Z' come before lower case `a', in accord with the ASCII
  158. character sequence.
  159.  
  160.    The various sort commands differ in how they divide the text into
  161. sort records and in which part of each record is used as the sort key.
  162. Most of the commands make each line a separate sort record, but some
  163. commands use paragraphs or pages as sort records.  Most of the sort
  164. commands use each entire sort record as its own sort key, but some use
  165. only a portion of the record as the sort key.
  166.  
  167. `M-x sort-lines'
  168.      Divide the region into lines, and sort by comparing the entire
  169.      text of a line.  A numeric argument means sort into descending
  170.      order.
  171.  
  172. `M-x sort-paragraphs'
  173.      Divide the region into paragraphs, and sort by comparing the entire
  174.      text of a paragraph (except for leading blank lines).  A numeric
  175.      argument means sort into descending order.
  176.  
  177. `M-x sort-pages'
  178.      Divide the region into pages, and sort by comparing the entire
  179.      text of a page (except for leading blank lines).  A numeric
  180.      argument means sort into descending order.
  181.  
  182. `M-x sort-fields'
  183.      Divide the region into lines, and sort by comparing the contents of
  184.      one field in each line.  Fields are defined as separated by
  185.      whitespace, so the first run of consecutive non-whitespace
  186.      characters in a line constitutes field 1, the second such run
  187.      constitutes field 2, etc.
  188.  
  189.      Specify which field to sort by with a numeric argument: 1 to sort
  190.      by field 1, etc.  A negative argument means count fields from the
  191.      right instead of from the left; thus, minus 1 means sort by the
  192.      last field.  If several lines have identical contents in the field
  193.      being sorted, they keep same relative order that they had in the
  194.      original buffer.
  195.  
  196.      A negative argument means count fields from the right (from the
  197.      end of the line).
  198.  
  199. `M-x sort-numeric-fields'
  200.      Like `M-x sort-fields' except the specified field is converted to
  201.      an integer for each line, and the numbers are compared.  `10'
  202.      comes before `2' when considered as text, but after it when
  203.      considered as a number.
  204.  
  205. `M-x sort-columns'
  206.      Like `M-x sort-fields' except that the text within each line used
  207.      for comparison comes from a fixed range of columns.  See below for
  208.      an explanation.
  209.  
  210. `M-x reverse-region'
  211.      Reverse the order of the lines in the region.  This is useful for
  212.      sorting into descending order by fields or columns, since those
  213.      sort commands do not have a feature for doing that.
  214.  
  215.    For example, if the buffer contains this:
  216.  
  217.      On systems where clash detection (locking of files being edited) is
  218.      implemented, Emacs also checks the first time you modify a buffer
  219.      whether the file has changed on disk since it was last visited or
  220.      saved.  If it has, you are asked to confirm that you want to change
  221.      the buffer.
  222.  
  223. applying `M-x sort-lines' to the entire buffer produces this:
  224.  
  225.      On systems where clash detection (locking of files being edited) is
  226.      implemented, Emacs also checks the first time you modify a buffer
  227.      saved.  If it has, you are asked to confirm that you want to change
  228.      the buffer.
  229.      whether the file has changed on disk since it was last visited or
  230.  
  231. where the upper case `O' sorts before all lower case letters.  If you
  232. use `C-u 2 M-x sort-fields' instead, you get this:
  233.  
  234.      implemented, Emacs also checks the first time you modify a buffer
  235.      saved.  If it has, you are asked to confirm that you want to change
  236.      the buffer.
  237.      On systems where clash detection (locking of files being edited) is
  238.      whether the file has changed on disk since it was last visited or
  239.  
  240. where the sort keys were `Emacs', `If', `buffer', `systems' and `the'.
  241.  
  242.    `M-x sort-columns' requires more explanation.  You specify the
  243. columns by putting point at one of the columns and the mark at the other
  244. column.  Because this means you cannot put point or the mark at the
  245. beginning of the first line to sort, this command uses an unusual
  246. definition of `region': all of the line point is in is considered part
  247. of the region, and so is all of the line the mark is in, as well as all
  248. the lines in between.
  249.  
  250.    For example, to sort a table by information found in columns 10 to
  251. 15, you could put the mark on column 10 in the first line of the table,
  252. and point on column 15 in the last line of the table, and then run
  253. `sort-columns'.  Equivalently, you could run it with the mark on column
  254. 15 in the first line and point on column 10 in the last line.
  255.  
  256.    This can be thought of as sorting the rectangle specified by point
  257. and the mark, except that the text on each line to the left or right of
  258. the rectangle moves along with the text inside the rectangle.  *Note
  259. Rectangles::.
  260.  
  261.    Many of the sort commands ignore case differences when comparing, if
  262. `sort-fold-case' is non-`nil'.
  263.  
  264. 
  265. File: emacs,  Node: Narrowing,  Next: Two-Column,  Prev: Sorting,  Up: Top
  266.  
  267. Narrowing
  268. =========
  269.  
  270.    "Narrowing" means focusing in on some portion of the buffer, making
  271. the rest temporarily inaccessible.  The portion which you can still get
  272. to is called the "accessible portion".  Canceling the narrowing, which
  273. makes the entire buffer once again accessible, is called "widening".
  274. The amount of narrowing in effect in a buffer at any time is called the
  275. buffer's "restriction".
  276.  
  277.    Narrowing can make it easier to concentrate on a single subroutine or
  278. paragraph by eliminating clutter.  It can also be used to restrict the
  279. range of operation of a replace command or repeating keyboard macro.
  280.  
  281. `C-x n n'
  282.      Narrow down to between point and mark (`narrow-to-region').
  283.  
  284. `C-x n w'
  285.      Widen to make the entire buffer accessible again (`widen').
  286.  
  287. `C-x n p'
  288.      Narrow down to the current page (`narrow-to-page').
  289.  
  290.    When you have narrowed down to a part of the buffer, that part
  291. appears to be all there is.  You can't see the rest, you can't move
  292. into it (motion commands won't go outside the accessible part), you
  293. can't change it in any way.  However, it is not gone, and if you save
  294. the file all the inaccessible text will be saved.  The word `Narrow'
  295. appears in the mode line whenever narrowing is in effect.
  296.  
  297.    The primary narrowing command is `C-x n n' (`narrow-to-region').  It
  298. sets the current buffer's restrictions so that the text in the current
  299. region remains accessible but all text before the region or after the
  300. region is inaccessible.  Point and mark do not change.
  301.  
  302.    Alternatively, use `C-x n p' (`narrow-to-page') to narrow down to
  303. the current page.  *Note Pages::, for the definition of a page.
  304.  
  305.    The way to cancel narrowing is to widen with `C-x n w' (`widen').
  306. This makes all text in the buffer accessible again.
  307.  
  308.    You can get information on what part of the buffer you are narrowed
  309. down to using the `C-x =' command.  *Note Position Info::.
  310.  
  311.    Because narrowing can easily confuse users who do not understand it,
  312. `narrow-to-region' is normally a disabled command.  Attempting to use
  313. this command asks for confirmation and gives you the option of enabling
  314. it; if you enable the command, confirmation will no longer be required
  315. for it.  *Note Disabling::.
  316.  
  317. 
  318. File: emacs,  Node: Two-Column,  Next: Editing Binary Files,  Prev: Narrowing,  Up: Top
  319.  
  320. Two-Column Editing
  321. ==================
  322.  
  323.    Two-column mode lets you conveniently edit two side-by-side columns
  324. of text.  It uses two side-by-side windows, each showing its own buffer.
  325.  
  326.    There are three ways to enter two-column mode:
  327.  
  328. `C-x 6 2'
  329.      Enter two-column mode with the current buffer on the left, and on
  330.      the right, a buffer whose name is based on the current buffer's
  331.      name (`tc-two-columns').  If the right-hand buffer doesn't already
  332.      exist, it starts out empty; the current buffer's contents are not
  333.      changed.
  334.  
  335.      This command is appropriate when the current buffer contains just
  336.      one column and you want to add another column.
  337.  
  338. `C-x 6 s'
  339.      Split the current buffer, which contains two-column text, into two
  340.      buffers, and display them side by side (`tc-split').  The current
  341.      buffer becomes the left-hand buffer, but the text in the right-hand
  342.      column is moved into the right-hand buffer.  The current column
  343.      specifies the split point.  Splitting starts with the current line
  344.      and continues to the end of the buffer.
  345.  
  346.      This command is appropriate when you have a buffer that already
  347.      contains two-column text, and you wish to separate the columns
  348.      temporarily.
  349.  
  350. `C-x 6 b BUFFER RET'
  351.      Enter two-column mode using the current buffer as the left-hand
  352.      buffer, and using buffer BUFFER as the right-hand buffer
  353.      (`tc-associate-buffer').
  354.  
  355.    `C-x 6 s' looks for a column separator which is a string that
  356. appears on each line between the two columns.  You can specify the width
  357. of the separator with a numeric argument to `C-x 6 s'; that many
  358. characters, before point, constitute the separator string.  By default,
  359. the width is 1, so the column separator is the character before point.
  360.  
  361.    When a line has the separator at the proper place, `C-x 6 s' puts
  362. the text after the separator into the right-hand buffer, and deletes the
  363. separator.  Lines that don't have the column separator at the proper
  364. place remain unsplit; they stay in the left-hand buffer, and the
  365. right-hand buffer gets an empty line to correspond.  (This is the way
  366. to write a line that spans both columns while in two-column mode: write
  367. it in the left-hand buffer, and put an empty line in the right-hand
  368. buffer.)
  369.  
  370.    It's not a good idea to use ordinary scrolling commands during
  371. two-column editing, because that separates the two parts of each split
  372. line.  Instead, use these special scroll commands:
  373.  
  374. `C-x 6 SPC'
  375.      Scroll both buffers up, in lock step (`tc-scroll-up').
  376.  
  377. `C-x 6 DEL'
  378.      Scroll both buffers down, in lock step (`tc-scroll-down').
  379.  
  380. `C-x 6 C-l'
  381.      Recenter both buffers, in lock step (`tc-recenter').
  382.  
  383.    When you have edited both buffers as you wish, merge them with `C-x
  384. 6 1' (`tc-merge').  This copies the text from the right-hand buffer as
  385. a second column in the other buffer.  To go back to two-column editing,
  386. use `C-x 6 s'.
  387.  
  388.    Use `C-x 6 d' to disassociate the two buffers, leaving each as it
  389. stands (`tc-dissociate').  If the other buffer, the one not current
  390. when you type `C-x 6 d', is empty, `C-x 6 d' kills it.
  391.  
  392. 
  393. File: emacs,  Node: Editing Binary Files,  Next: Saving Emacs Sessions,  Prev: Two-Column,  Up: Top
  394.  
  395. Editing Binary Files
  396. ====================
  397.  
  398.    There is a special major mode for editing binary files: Hexl mode.
  399. To use it, use `M-x hexl-find-file' instead of `C-x C-f' to visit the
  400. file.  This command converts the file's contents to hexadecimal and
  401. lets you edit the translation.  When you save the file, it is converted
  402. automatically back to binary.
  403.  
  404.    You can also use `M-x hexl-mode' to translate an existing buffer
  405. into hex.  This is useful if you visit a file normally and then discover
  406. it is a binary file.
  407.  
  408.    Ordinary text characters overwrite in Hexl mode.  This is to reduce
  409. the risk of accidentally spoiling the alignment of data in the file.
  410. There are special commands for insertion.  Here is a list of the
  411. commands of Hexl mode:
  412.  
  413. `C-M-d'
  414.      Insert a byte with a code typed in decimal.
  415.  
  416. `C-M-o'
  417.      Insert a byte with a code typed in octal.
  418.  
  419. `C-M-x'
  420.      Insert a byte with a code typed in hex.
  421.  
  422. `C-x ['
  423.      Move to the beginning of a 1k-byte "page".
  424.  
  425. `C-x ]'
  426.      Move to the end of a 1k-byte "page".
  427.  
  428. `M-g'
  429.      Move to an address specified in hex.
  430.  
  431. `M-j'
  432.      Move to an address specified in decimal.
  433.  
  434. `C-c C-c'
  435.      Leave Hexl mode, going back to the major mode this buffer had
  436.      before you invoked `hexl-mode'.
  437.  
  438. 
  439. File: emacs,  Node: Saving Emacs Sessions,  Next: Recursive Edit,  Prev: Editing Binary Files,  Up: Top
  440.  
  441. Saving Emacs Sessions
  442. =====================
  443.  
  444.    You can use the Desktop library to save the state of Emacs from one
  445. session to another.  Saving the state means that Emacs starts up with
  446. the same set of buffers, major modes, buffer positions, and so on that
  447. the previous Emacs session had.
  448.  
  449.    To use Desktop, you should first add these lines to your `.emacs'
  450. file, preferably at or near the end:
  451.  
  452.      (load "desktop")
  453.      (desktop-load-default)
  454.      (desktop-read)
  455.  
  456. Then, to enable state saving in a particular Emacs session, use the
  457. command `M-x desktop-save'.  Once you have done this, the state of this
  458. Emacs session will be saved when you exit Emacs.
  459.  
  460.    In order for Emacs to recover the state from a previous session, you
  461. must start it with the same current directory as you used when you
  462. started the previous session.
  463.  
  464. 
  465. File: emacs,  Node: Recursive Edit,  Next: Emulation,  Prev: Saving Emacs Sessions,  Up: Top
  466.  
  467. Recursive Editing Levels
  468. ========================
  469.  
  470.    A "recursive edit" is a situation in which you are using Emacs
  471. commands to perform arbitrary editing while in the middle of another
  472. Emacs command.  For example, when you type `C-r' inside of a
  473. `query-replace', you enter a recursive edit in which you can change the
  474. current buffer.  On exiting from the recursive edit, you go back to the
  475. `query-replace'.
  476.  
  477.    "Exiting" the recursive edit means returning to the unfinished
  478. command, which continues execution.  The command to exit is `C-M-c'
  479. (`exit-recursive-edit').
  480.  
  481.    You can also "abort" the recursive edit.  This is like exiting, but
  482. also quits the unfinished command immediately.  Use the command `C-]'
  483. (`abort-recursive-edit') to do this.  *Note Quitting::.
  484.  
  485.    The mode line shows you when you are in a recursive edit by
  486. displaying square brackets around the parentheses that always surround
  487. the major and minor mode names.  Every window's mode line shows this,
  488. in the same way, since being in a recursive edit is true of Emacs as a
  489. whole rather than any particular window or buffer.
  490.  
  491.    It is possible to be in recursive edits within recursive edits.  For
  492. example, after typing `C-r' in a `query-replace', you may type a
  493. command that enters the debugger.  This begins a recursive editing level
  494. for the debugger, within the recursive editing level for `C-r'.  Mode
  495. lines display a pair of square brackets for each recursive editing
  496. level currently in progress.
  497.  
  498.    Exiting the inner recursive edit (such as, with the debugger `c'
  499. command) resumes the command running in the next level up.  When that
  500. command finishes, you can then use `C-M-c' to exit another recursive
  501. editing level, and so on.  Exiting applies to the innermost level only.
  502. Aborting also gets out of only one level of recursive edit; it returns
  503. immediately to the command level of the previous recursive edit.  If you
  504. wish, you can then abort the next recursive editing level.
  505.  
  506.    Alternatively, the command `M-x top-level' aborts all levels of
  507. recursive edits, returning immediately to the top level command reader.
  508.  
  509.    The text being edited inside the recursive edit need not be the same
  510. text that you were editing at top level.  It depends on what the
  511. recursive edit is for.  If the command that invokes the recursive edit
  512. selects a different buffer first, that is the buffer you will edit
  513. recursively.  In any case, you can switch buffers within the recursive
  514. edit in the normal manner (as long as the buffer-switching keys have
  515. not been rebound).  You could probably do all the rest of your editing
  516. inside the recursive edit, visiting files and all.  But this could have
  517. surprising effects (such as stack overflow) from time to time.  So
  518. remember to exit or abort the recursive edit when you no longer need it.
  519.  
  520.    In general, we try to minimize the use of recursive editing levels in
  521. GNU Emacs.  This is because they constrain you to "go back" in a
  522. particular order-from the innermost level toward the top level.  When
  523. possible, we present different activities in separate buffers so that
  524. you can switch between them as you please.  Some commands switch to a
  525. new major mode which provides a command to switch back.  These
  526. approaches give you more flexibility to go back to unfinished tasks in
  527. the order you choose.
  528.  
  529. 
  530. File: emacs,  Node: Emulation,  Next: Dissociated Press,  Prev: Recursive Edit,  Up: Top
  531.  
  532. Emulation
  533. =========
  534.  
  535.    GNU Emacs can be programmed to emulate (more or less) most other
  536. editors.  Standard facilities can emulate these:
  537.  
  538. EDT (DEC VMS editor)
  539.      Turn on EDT emulation with `M-x edt-emulation-on'.  `M-x
  540.      edt-emulation-off' restores normal Emacs command bindings.
  541.  
  542.      Most of the EDT emulation commands are keypad keys, and most
  543.      standard Emacs key bindings are still available.  The EDT
  544.      emulation rebindings are done in the global keymap, so there is no
  545.      problem switching buffers or major modes while in EDT emulation.
  546.  
  547. vi (Berkeley editor)
  548.      Turn on vi emulation with `M-x vi-mode'.  This is a major mode
  549.      that replaces the previously established major mode.  All of the
  550.      vi commands that, in real vi, enter "input" mode are programmed in
  551.      the Emacs emulator to return to the previous major mode.  Thus,
  552.      ordinary Emacs serves as vi's "input" mode.
  553.  
  554.      Because vi emulation works through major modes, it does not work
  555.      to switch buffers during emulation.  Return to normal Emacs first.
  556.  
  557.      If you plan to use vi emulation much, you probably want to bind a
  558.      key to the `vi-mode' command.
  559.  
  560. vi (alternate emulator)
  561.      Another vi emulator said to resemble real vi more thoroughly is
  562.      invoked by `M-x vip-mode'.  "Input" mode in this emulator is
  563.      changed from ordinary Emacs so you can use ESC to go back to
  564.      emulated vi command mode.  To get from emulated vi command mode
  565.      back to ordinary Emacs, type `C-z'.
  566.  
  567.      This emulation does not work through major modes, and it is
  568.      possible to switch buffers in various ways within the emulator.
  569.      It is not so necessary to assign a key to the command `vip-mode' as
  570.      it is with `vi-mode' because terminating insert mode does not use
  571.      it.
  572.  
  573.      For full information, see the long comment at the beginning of the
  574.      source file, which is `lisp/vip.el' in the Emacs distribution.
  575.  
  576.    I am interested in hearing which vi emulator users prefer, as well
  577. as in receiving more complete user documentation for either or both
  578. emulators.  Warning: loading both vi emulators at once may cause name
  579. conflicts; no one has checked.
  580.  
  581. 
  582. File: emacs,  Node: Dissociated Press,  Next: Amusements,  Prev: Emulation,  Up: Top
  583.  
  584. Dissociated Press
  585. =================
  586.  
  587.    `M-x dissociated-press' is a command for scrambling a file of text
  588. either word by word or character by character.  Starting from a buffer
  589. of straight English, it produces extremely amusing output.  The input
  590. comes from the current Emacs buffer.  Dissociated Press writes its
  591. output in a buffer named `*Dissociation*', and redisplays that buffer
  592. after every couple of lines (approximately) so you can read the output
  593. as it comes out.
  594.  
  595.    Dissociated Press asks every so often whether to continue generating
  596. output.  Answer `n' to stop it.  You can also stop at any time by
  597. typing `C-g'.  The dissociation output remains in the `*Dissociation*'
  598. buffer for you to copy elsewhere if you wish.
  599.  
  600.    Dissociated Press operates by jumping at random from one point in the
  601. buffer to another.  In order to produce plausible output rather than
  602. gibberish, it insists on a certain amount of overlap between the end of
  603. one run of consecutive words or characters and the start of the next.
  604. That is, if it has just printed out `president' and then decides to jump
  605. to a different point in the file, it might spot the `ent' in `pentagon'
  606. and continue from there, producing `presidentagon'.(1)  Long sample
  607. texts produce the best results.
  608.  
  609.    A positive argument to `M-x dissociated-press' tells it to operate
  610. character by character, and specifies the number of overlap characters.
  611. A negative argument tells it to operate word by word and specifies the
  612. number of overlap words.  In this mode, whole words are treated as the
  613. elements to be permuted, rather than characters.  No argument is
  614. equivalent to an argument of two.  For your againformation, the output
  615. goes only into the buffer `*Dissociation*'.  The buffer you start with
  616. is not changed.
  617.  
  618.    Dissociated Press produces nearly the same results as a Markov chain
  619. based on a frequency table constructed from the sample text.  It is,
  620. however, an independent, ignoriginal invention.  Dissociated Press
  621. techniquitously copies several consecutive characters from the sample
  622. between random choices, whereas a Markov chain would choose randomly for
  623. each word or character.  This makes for more plausible sounding results,
  624. and runs faster.
  625.  
  626.    It is a mustatement that too much use of Dissociated Press can be a
  627. developediment to your real work.  Sometimes to the point of outragedy.
  628. And keep dissociwords out of your documentation, if you want it to be
  629. well userenced and properbose.  Have fun.  Your buggestions are welcome.
  630.  
  631.    ---------- Footnotes ----------
  632.  
  633.    (1)  This dissociword actually appeared during the Vietnam War, when
  634. it was very appropriate.
  635.  
  636. 
  637. File: emacs,  Node: Amusements,  Next: Customization,  Prev: Dissociated Press,  Up: Top
  638.  
  639. Other Amusements
  640. ================
  641.  
  642.    If you are a little bit bored, you can try `M-x hanoi'.  If you are
  643. considerably bored, give it a numeric argument.  If you are very very
  644. bored, try an argument of 9.  Sit back and watch.
  645.  
  646.    If you want a little more personal involvement, try `M-x gomoku',
  647. which plays the game Go Moku with you.
  648.  
  649.    `M-x blackbox' and `M-x mpuz' are two kinds of puzzles.  `blackbox'
  650. challenges you to determine the location of objects inside a box by
  651. tomography.  `mpuz' displays a multiplication puzzle with letters
  652. standing for digits in a code that you must guess--to guess a value,
  653. type a letter and then the digit you think it stands for.
  654.  
  655.    `M-x dunnet' runs an adventure-style exploration game, which is a
  656. bigger sort of puzzle.
  657.  
  658.    When you are frustrated, try the famous Eliza program.  Just do `M-x
  659. doctor'.  End each input by typing `RET' twice.
  660.  
  661.    When you are feeling strange, type `M-x yow'.
  662.  
  663. 
  664. File: emacs,  Node: Customization,  Next: Quitting,  Prev: Amusements,  Up: Top
  665.  
  666. Customization
  667. *************
  668.  
  669.    This chapter talks about various topics relevant to adapting the
  670. behavior of Emacs in minor ways.  See `The Emacs Lisp Reference Manual'
  671. for how to make more far-reaching changes.
  672.  
  673.    All kinds of customization affect only the particular Emacs session
  674. that you do them in.  They are completely lost when you kill the Emacs
  675. session, and have no effect on other Emacs sessions you may run at the
  676. same time or later.  The only way an Emacs session can affect anything
  677. outside of it is by writing a file; in particular, the only way to make
  678. a customization `permanent' is to put something in your `.emacs' file
  679. or other appropriate file to do the customization in each session.
  680. *Note Init File::.
  681.  
  682. * Menu:
  683.  
  684. * Minor Modes::           Each minor mode is one feature you can turn on
  685.                  independently of any others.
  686. * Variables::           Many Emacs commands examine Emacs variables
  687.                  to decide what to do; by setting variables,
  688.                  you can control their functioning.
  689. * Keyboard Macros::       A keyboard macro records a sequence of
  690.                  keystrokes to be replayed with a single
  691.                  command.
  692. * Key Bindings::       The keymaps say what command each key runs.
  693.                  By changing them, you can "redefine keys".
  694. * Keyboard Translations::  If your keyboard passes an undesired code
  695.                  for a key, you can tell Emacs to
  696.                  substitute another code.
  697. * Syntax::           The syntax table controls how words and
  698.                   expressions are parsed.
  699. * Init File::           How to write common customizations in the
  700.                              `.emacs' file.
  701.  
  702. 
  703. File: emacs,  Node: Minor Modes,  Next: Variables,  Up: Customization
  704.  
  705. Minor Modes
  706. ===========
  707.  
  708.    Minor modes are optional features which you can turn on or off.  For
  709. example, Auto Fill mode is a minor mode in which SPC breaks lines
  710. between words as you type.  All the minor modes are independent of each
  711. other and of the selected major mode.  Most minor modes say in the mode
  712. line when they are on; for example, `Fill' in the mode line means that
  713. Auto Fill mode is on.
  714.  
  715.    Append `-mode' to the name of a minor mode to get the name of a
  716. command function that turns the mode on or off.  Thus, the command to
  717. enable or disable Auto Fill mode is called `M-x auto-fill-mode'.  These
  718. commands are usually invoked with `M-x', but you can bind keys to them
  719. if you wish.  With no argument, the function turns the mode on if it was
  720. off and off if it was on.  This is known as "toggling".  A positive
  721. argument always turns the mode on, and an explicit zero argument or a
  722. negative argument always turns it off.
  723.  
  724.    Enabling or disabling some minor modes applies only to the current
  725. buffer; each buffer is independent of the other buffers.  Therefore, you
  726. can enable the mode in particular buffers and disable it in others.  The
  727. per-buffer minor modes include Auto Fill mode, Outline minor mode, Auto
  728. Save mode, Font-Lock mode, and ISO Accents mode.
  729.  
  730.    Auto Fill mode allows you to enter filled text without breaking lines
  731. explicitly.  Emacs inserts newlines as necessary to prevent lines from
  732. becoming too long.  *Note Filling::.
  733.  
  734.    Outline minor mode provides the same facilities as the major mode
  735. called Outline mode; but since it is a minor mode instead, you can
  736. combine it with any major mode.  *Note Outline Mode::.
  737.  
  738.    Overwrite mode causes ordinary printing characters to replace
  739. existing text instead of shoving it to the right.  For example, if
  740. point is in front of the `B' in `FOOBAR', then in Overwrite mode typing
  741. a `G' changes it to `FOOGAR', instead of producing it `FOOGBAR' as
  742. usual.
  743.  
  744.    Auto Save mode causes the contents of a buffer to be saved
  745. periodically to reduce the amount of work you can lose in case of a
  746. system crash.  *Note Auto Save::.
  747.  
  748.    Font-Lock mode automatically highlights certain textual units found
  749. in programs, such as comments, strings, and function names being
  750. defined.  This requires a window system that can display multiple fonts.
  751. *Note Faces::.
  752.  
  753.    ISO Accents mode makes the characters ``', `'', `"', `^', `/' and
  754. `~' combine with the following letter, to produce an accented letter in
  755. the ISO Latin-1 character set.  *Note European Display::.
  756.  
  757.    The following minor modes normally apply to all buffers at once.
  758. Since each is enabled or disabled by the value of a variable, you *can*
  759. set them differently for particular buffers, by explicitly making the
  760. corresponding variables local in those buffers.  *Note Locals::.
  761.  
  762.    Abbrev mode allows you to define abbreviations that automatically
  763. expand as you type them.  For example, `amd' might expand to `abbrev
  764. mode'.  *Note Abbrevs::, for full information.
  765.  
  766.    Line Number mode enables continuous display in the mode line of the
  767. line number of point.  *Note Mode Line::.
  768.  
  769.    Resize-Minibuffer mode makes the minibuffer expand as necessary to
  770. hold the text that you put in it.  *Note Minibuffer Edit::.
  771.  
  772.    Scroll Bar mode gives each window a scroll bar (*note Scroll
  773. Bars::.).  Menu Bar mode gives each frame a menu bar (*note Menu
  774. Bars::.).  Both of these modes are enabled by default when you use the
  775. X Window System.
  776.  
  777.    In Transient Mark mode, every change in the buffer contents
  778. "deactivates" the mark, so that commands that operate on the region
  779. will get an error.  This means you must either set the mark, or
  780. explicitly "reactivate" it, before each command that uses the region.
  781. The advantage of Transient Mark mode is that Emacs can display the
  782. region highlighted (currently only when using X).  *Note Setting Mark::.
  783.  
  784. 
  785. File: emacs,  Node: Variables,  Next: Keyboard Macros,  Prev: Minor Modes,  Up: Customization
  786.  
  787. Variables
  788. =========
  789.  
  790.    A "variable" is a Lisp symbol which has a value.  The symbol's name
  791. is also called the name of the variable.  A variable name can contain
  792. any characters that can appear in a file, but conventionally variable
  793. names consist of words separated by hyphens.  A variable can have a
  794. documentation string which describes what kind of value it should have
  795. and how the value will be used.
  796.  
  797.    Lisp allows any variable to have any kind of value, but most
  798. variables that Emacs uses require a value of a certain type.  Often the
  799. value should always be a string, or should always be a number.
  800. Sometimes we say that a certain feature is turned on if a variable is
  801. "non-`nil'," meaning that if the variable's value is `nil', the feature
  802. is off, but the feature is on for *any* other value.  The conventional
  803. value to use to turn on the feature--since you have to pick one
  804. particular value when you set the variable--is `t'.
  805.  
  806.    Emacs uses many Lisp variables for internal record keeping, as any
  807. Lisp program must, but the most interesting variables for you are the
  808. ones that exist for the sake of customization.  Emacs does not
  809. (usually) change the values of these variables; instead, you set the
  810. values, and thereby alter and control the behavior of certain Emacs
  811. commands.  These variables are called "options".  Most options are
  812. documented in this manual, and appear in the Variable Index (*note
  813. Variable Index::.).
  814.  
  815.    One example of a variable which is an option is `fill-column', which
  816. specifies the position of the right margin (as a number of characters
  817. from the left margin) to be used by the fill commands (*note
  818. Filling::.).
  819.  
  820. * Menu:
  821.  
  822. * Examining::         Examining or setting one variable's value.
  823. * Edit Options::     Examining or editing list of all variables' values.
  824. * Hooks::         Hook variables let you specify programs for parts
  825.                of Emacs to run on particular occasions.
  826. * Locals::         Per-buffer values of variables.
  827. * File Variables::   How files can specify variable values.
  828.  
  829. 
  830. File: emacs,  Node: Examining,  Next: Edit Options,  Up: Variables
  831.  
  832. Examining and Setting Variables
  833. -------------------------------
  834.  
  835. `C-h v VAR RET'
  836.      Display the value and documentation of variable VAR
  837.      (`describe-variable').
  838.  
  839. `M-x set-variable RET VAR RET VALUE RET'
  840.      Change the value of variable VAR to VALUE.
  841.  
  842.    To examine the value of a single variable, use `C-h v'
  843. (`describe-variable'), which reads a variable name using the
  844. minibuffer, with completion.  It displays both the value and the
  845. documentation of the variable.  For example,
  846.  
  847.      C-h v fill-column RET
  848.  
  849. displays something like this:
  850.  
  851.      fill-column's value is 75
  852.      
  853.      Documentation:
  854.      *Column beyond which automatic line-wrapping should happen.
  855.      Automatically becomes buffer-local when set in any fashion.
  856.  
  857. The star at the beginning of the documentation indicates that this
  858. variable is an option.  `C-h v' is not restricted to options; it allows
  859. any variable name.
  860.  
  861.    The most convenient way to set a specific option is with `M-x
  862. set-variable'.  This reads the variable name with the minibuffer (with
  863. completion), and then reads a Lisp expression for the new value using
  864. the minibuffer a second time.  For example,
  865.  
  866.      M-x set-variable RET fill-column RET 75 RET
  867.  
  868. sets `fill-column' to 75.
  869.  
  870.    You can set any variable with a Lisp expression using the function
  871. `setq'.  Here's how to use it to set `fill-column':
  872.  
  873.      (setq fill-column 75)
  874.  
  875.    Setting variables, like all means of customizing Emacs except where
  876. otherwise stated, affects only the current Emacs session.
  877.  
  878. 
  879. File: emacs,  Node: Edit Options,  Next: Hooks,  Prev: Examining,  Up: Variables
  880.  
  881. Editing Variable Values
  882. -----------------------
  883.  
  884.    These two functions make it easy to display all the Emacs option
  885. variables, and to change some of them if you wish.
  886.  
  887. `M-x list-options'
  888.      Display a buffer listing names, values and documentation of all
  889.      options.
  890.  
  891. `M-x edit-options'
  892.      Change option values by editing a list of options.
  893.  
  894.    `M-x list-options' displays a list of all Emacs option variables, in
  895. an Emacs buffer named `*List Options*'.  Each option is shown with its
  896. documentation and its current value.  Here is what a portion of it might
  897. look like:
  898.  
  899.      ;; exec-path:
  900.      ("." "/usr/local/bin" "/usr/ucb" "/bin" "/usr/bin" "/u2/emacs/etc")
  901.      *List of directories to search programs to run in subprocesses.
  902.      Each element is a string (directory name)
  903.      or nil (try the default directory).
  904.      ;;
  905.      ;; fill-column:
  906.      75
  907.      *Column beyond which automatic line-wrapping should happen.
  908.      Automatically becomes buffer-local when set in any fashion.
  909.      ;;
  910.  
  911.    `M-x edit-options' goes one step further and immediately selects the
  912. `*List Options*' buffer; this buffer uses the major mode Options mode,
  913. which provides commands that allow you to point at an option and change
  914. its value:
  915.  
  916. `s'
  917.      Set the variable point is in or near to a new value read using the
  918.      minibuffer.
  919.  
  920. `x'
  921.      Toggle the variable point is in or near: if the value was `nil',
  922.      it becomes `t'; otherwise it becomes `nil'.
  923.  
  924. `1'
  925.      Set the variable point is in or near to `t'.
  926.  
  927. `0'
  928.      Set the variable point is in or near to `nil'.
  929.  
  930. `n'
  931. `p'
  932.      Move to the next or previous variable.
  933.  
  934.    Any changes take effect immediately, and last until you exit from
  935. Emacs.
  936.  
  937. 
  938. File: emacs,  Node: Hooks,  Next: Locals,  Prev: Edit Options,  Up: Variables
  939.  
  940. Hooks
  941. -----
  942.  
  943.    A "hook" is a variable where you can store a function or functions
  944. to be called on a particular occasion by an existing program.  Emacs
  945. provides a number of hooks for the sake of customization.
  946.  
  947.    Most of the hooks in Emacs are "normal hooks".  These variables
  948. contain lists of functions to be called with no arguments.  The reason
  949. most hooks are normal hooks is so that you can use them in a uniform
  950. way.  Every variable in Emacs whose name ends in `-hook' is a normal
  951. hook.
  952.  
  953.    Most major modes run hooks as the last step of initialization.  This
  954. makes it easy for a user to customize the behavior of the mode, by
  955. overriding the local variable assignments already made by the mode.  But
  956. hooks may also be used in other contexts.  For example, the hook
  957. `suspend-hook' runs just before Emacs suspends itself (*note
  958. Exiting::.).
  959.  
  960.    The recommended way to add a hook function to a normal hook is by
  961. calling `add-hook'.  You can use any valid Lisp function as the hook
  962. function.  For example, here's how to set up a hook to turn on Auto
  963. Fill mode when entering Text mode and other modes based on Text mode:
  964.  
  965.      (add-hook 'text-mode-hook 'turn-on-auto-fill)
  966.  
  967.    The next example shows how to use a hook to customize the indentation
  968. of C code.  (People often have strong personal preferences for one
  969. format compared to another.)  Here the hook function is an anonymous
  970. lambda expression.
  971.  
  972.      (add-hook 'c-mode-hook
  973.        (function (lambda ()
  974.                    (setq c-indent-level 4
  975.                          c-argdecl-indent 0
  976.                          c-label-offset -4
  977.                          c-continued-statement-indent 0
  978.                          c-brace-offset 0
  979.                          comment-column 40))))
  980.      
  981.      (setq c++-mode-hook c-mode-hook)
  982.  
  983.    It is best to design your hook functions so that the order in which
  984. they are executed does not matter.  Any dependence on the order is
  985. "asking for trouble."  However, the order is predictable: the most
  986. recently added hook functions are executed first.
  987.  
  988. 
  989. File: emacs,  Node: Locals,  Next: File Variables,  Prev: Hooks,  Up: Variables
  990.  
  991. Local Variables
  992. ---------------
  993.  
  994. `M-x make-local-variable RET VAR RET'
  995.      Make variable VAR have a local value in the current buffer.
  996.  
  997. `M-x kill-local-variable RET VAR RET'
  998.      Make variable VAR use its global value in the current buffer.
  999.  
  1000. `M-x make-variable-buffer-local RET VAR RET'
  1001.      Mark variable VAR so that setting it will make it local to the
  1002.      buffer that is current at that time.
  1003.  
  1004.    Any variable can be made "local" to a specific Emacs buffer.  This
  1005. means that its value in that buffer is independent of its value in other
  1006. buffers.  A few variables are always local in every buffer.  Every other
  1007. Emacs variable has a "global" value which is in effect in all buffers
  1008. that have not made the variable local.
  1009.  
  1010.    `M-x make-local-variable' reads the name of a variable and makes it
  1011. local to the current buffer.  Further changes in this buffer will not
  1012. affect others, and further changes in the global value will not affect
  1013. this buffer.
  1014.  
  1015.    `M-x make-variable-buffer-local' reads the name of a variable and
  1016. changes the future behavior of the variable so that it will become local
  1017. automatically when it is set.  More precisely, once a variable has been
  1018. marked in this way, the usual ways of setting the variable automatically
  1019. do `make-local-variable' first.  We call such variables "per-buffer"
  1020. variables.
  1021.  
  1022.    Major modes (*note Major Modes::.) always make variables local to the
  1023. buffer before setting the variables.  This is why changing major modes
  1024. in one buffer has no effect on other buffers.  Minor modes also work by
  1025. setting variables--normally, each minor mode has one controlling
  1026. variable which is non-`nil' when the mode is enabled (*note Minor
  1027. Modes::.).  For most minor modes, the controlling variable is per
  1028. buffer.
  1029.  
  1030.    Emacs contains a number of variables that are always per-buffer.
  1031. These include `abbrev-mode', `auto-fill-function', `case-fold-search',
  1032. `comment-column', `ctl-arrow', `fill-column', `fill-prefix',
  1033. `indent-tabs-mode', `left-margin', `mode-line-format', `overwrite-mode',
  1034. `selective-display-ellipses', `selective-display', `tab-width', and
  1035. `truncate-lines'.  Some other variables are always local in every
  1036. buffer, but they are used for internal purposes.
  1037.  
  1038.    `M-x kill-local-variable' reads the name of a variable and makes it
  1039. cease to be local to the current buffer.  The global value of the
  1040. variable henceforth is in effect in this buffer.  Setting the major mode
  1041. kills all the local variables of the buffer except for a few variables
  1042. specially marked as "permanent locals".
  1043.  
  1044.    To set the global value of a variable, regardless of whether the
  1045. variable has a local value in the current buffer, you can use the Lisp
  1046. construct `setq-default'.  This construct is used just like `setq', but
  1047. it sets variables' global values instead of their local values (if
  1048. any).  When the current buffer does have a local value, the new global
  1049. value may not be visible until you switch to another buffer.  Here is
  1050. an example:
  1051.  
  1052.      (setq-default fill-column 75)
  1053.  
  1054. `setq-default' is the only way to set the global value of a variable
  1055. that has been marked with `make-variable-buffer-local'.
  1056.  
  1057.    Lisp programs can use `default-value' to look at a variable's
  1058. default value.  This function takes a symbol as argument and returns its
  1059. default value.  The argument is evaluated; usually you must quote it
  1060. explicitly.  For example, here's how to obtain the default value of
  1061. `fill-column':
  1062.  
  1063.      (default-value 'fill-column)
  1064.  
  1065.